<template>
  <div
    class="stat-box-container"
    @mouseenter="handleMouseEnter"
    @mouseleave="handleMouseLeave"
  >
    <!-- 主统计值显示 -->
    <div class="stat-main">
      <div class="stat-title">{{ title }}</div>
      <div class="stat-value">
        {{ value }}<span class="stat-unit">人</span>
      </div>
    </div>

    <!-- 悬停时显示的详细统计 -->
    <div class="stats-overlay" v-show="showStats">
      <div class="stat-item">
        <span class="stat-label">男性:</span>
        <span class="stat-value">{{ stats.male }}人</span>
      </div>
      <div class="stat-item">
        <span class="stat-label">女性:</span>
        <span class="stat-value">{{ stats.female }}人</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StatBox',
  props: {
    title: {
      type: String,
      required: true
    },
    value: {
      type: Number,
      required: true
    },
    stats: {
      type: Object,
      required: true,
      validator: value => {
        return 'male' in value && 'female' in value;
      }
    }
  },
  data() {
    return {
      showStats: false
    }
  },
  methods: {
    handleMouseEnter() {
      this.showStats = true;
    },
    handleMouseLeave() {
      this.showStats = false;
    }
  }
}
</script>

<style scoped>
/* 统计框容器样式 */
.stat-box-container {
  width: 305px;
  height: 305px;
  background: url('../../assets/images/leftren.png') no-repeat top center;
  background-size: cover;
  position: relative;
  cursor: pointer;
  font-size: 24px;
  transition: all 0.3s ease;
}

/* 主统计区域样式 */
.stat-main {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 100%;
}

.stat-title {
  height: 60px;
  line-height: 60px;
  color: #e6e6e6;
}

.stat-value {
  height: 40px;
  line-height: 40px;
  font-weight: bold;
  color: #ffcc00;
}

.stat-unit {
  font-size: 0.8em;
  margin-left: 5px;
  color: #e6e6e6;
}

/* 悬停详情样式 */
.stats-overlay {
  position: absolute;
  top: 150px;
  left: 150px;
  width: 232px;
  height: 115px;
  background: url('../../assets/images/hoverbg.png') no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 24px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.stat-box-container:hover .stats-overlay {
  opacity: 1;
}

.stat-item {
  margin: 10px 0;
  display: flex;
  align-items: center;
}

.stat-label {
  margin-right: 10px;
  color: #e6e6e6;
}

.stats-overlay .stat-value {
  font-weight: bold;
  color: #ffcc00;
}

/* 悬停动画效果 */
.stat-box-container:hover {
  transform: scale(1.05);
}
</style>
